<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {

	function __construct()
	 {
		parent::__construct();
		$this->load->helper('url');
	 }

	 private function htmlstr_loginbar(){
		$data=array();
		$this->load->library('tank_auth');
		$this->lang->load('tank_auth');
		if ($this->tank_auth->is_logged_in()){
			$data['login_username']=$this->tank_auth->get_username();
		}else{
			$data['login_username']='';
		}
		$htmlstr=$this->load->view('htmlpage/loginbar',$data,true);
		return $htmlstr;
	}
	private function get_share_pagedata(){
//		$pagedata['head']=$this->load->view('htmlpage/head','',true);
//		$pagedata['logobar']=$this->load->view('htmlpage/logobar','',true);
		$pagedata['loginbar']=$this->htmlstr_loginbar();
//		$pagedata['navbar']=$this->load->view('htmlpage/navbar','',true);
//		$pagedata['footbar']=$this->load->view('htmlpage/footbar','',true);
		return $pagedata;
	}

	//    默认版本，在master分支下和develop分支下不同
    public function index()
	{
		$this->load->helper('url');
		// 根据环境定义展示不同首页
		// $this->load->view(ENVIRONMENT,$this->get_share_pagedata());
		switch ($_SERVER['SERVER_NAME']){
			case 'urlbook.pc.ttd':
			case 'urlbook.thinktodo.cn':
			case 'urlbook.cn':
			case 'www.urlbook.cn':
				$viewName = '/urlbook.cn/index';
				$this->load->view($viewName,$this->get_share_pagedata());
				break;
			case 'hbz.pc.ttd':
			case '12369.xyz':
				$viewName = '/12369.xyz/index';
				$this->load->view($viewName,$this->get_share_pagedata());
				break;
			default:
				$this->load->view(ENVIRONMENT,$this->get_share_pagedata());

		}
		// $this->load->view(ENVIRONMENT,$this->get_share_pagedata());
	}

	// 生产环境版本
	public function pro()
	{
		$this->load->helper('url');
		$this->load->view('production',$this->get_share_pagedata());
	}

	//    测试环境版本
	public function tes()
	{
		$this->load->helper('url');
		$this->load->view('testing',$this->get_share_pagedata());
	}

	//    开发环境版本
	public function dev()
	{
		$this->load->helper('url');
		$this->load->view('development',$this->get_share_pagedata());
	}

	// 任意指定视图名
	public function x($viewname)
	{
		$this->load->helper('url');
		$this->load->view($viewname,$this->get_share_pagedata());
	}

	public function cal()
	{
		$this->load->helper('url');
		$this->load->view('calandar');
	}
	// 指定根节点
	public function n($taskid=1){
		$this->load->helper('url');
		$data = array();
		$data = $this->get_share_pagedata();
		$data['rootTaskId'] = $taskid;
		$this->load->view('node',$data);
	}
//    多工作区版本
	public function w($workarea=0)
	{
		if($workarea==1){
			$this->load->library('tank_auth');
			$this->lang->load('tank_auth');
			$this->load->database();
			$this->db->where('uid', $this->tank_auth->get_user_id());
			$this->db->order_by('in_date','desc');
			$this->db->limit(1,0);
			$query = $this->db->get('workarea');
			if ($query->num_rows() > 0)
			{
				$row = $query->row_array();
				$workarea=$row['id'];
//				print_r($row);
			}else{
				$workarea=0;
			}
		}
		$pagedata['loginbar']=$this->htmlstr_loginbar();
		$pagedata['workarea']=$workarea;
		$this->load->view('home292',$pagedata);
	}
//    分节点版本
	public function node($taskid=1){
		$this->load->helper('url');
		$data = array();
		$data = $this->get_share_pagedata();
		$data['rootTaskId'] = $taskid;
		$this->load->view('node',$data);
	}
//	单节点展示样式
	public function open($taskid=1){
		$this->load->helper('url');
		$data = array();
		$data = $this->get_share_pagedata();
		$data['rootTaskId'] = $taskid;
		$this->load->view('open',$data);
	}
//    脑图样式
	public function brain($taskid){
		$this->load->helper('url');
		$this->load->view('brain',$this->get_share_pagedata());
	}
	//  泡泡龙
	public function paopaolong($taskid){
		$this->load->helper('url');
		$data = array();
		$data = $this->get_share_pagedata();
		$data['rootTaskId'] = $taskid;
		$this->load->view('paopaolong',$data);
	}
//    导航样式
	public function daohang($taskid){
		$this->load->helper('url');
		$this->load->view('daohang',$this->get_share_pagedata());
	}
	//    收藏集样式
	public function urlbook($taskid){
		$this->load->helper('url');

		$data = array();
		$data = $this->get_share_pagedata();
		$data['rootTaskId'] = $taskid;
		$this->load->view('urlbook',$data);
	}
//    使用react的样式
	public function react($view){
		$this->load->helper('url');
		$this->load->view('react/'.$view,$this->get_share_pagedata());
	}
}
